import data from './data.js'
const {
  records,
  cate_1,
  cate_2,
  cate_3,
  cate_attr_list,
  spu_records,
  spu_imglist,
  spu_attrlist,
  sku_list,
  user_list,
  role_list,
  ROLE_MY_LIST,
  ALL_ROLE_LIST,
  saleattr_records,
} = data
//用户信息数据
function createUserList() {
  return [
    {
      userId: 1,
      avatar:
        'https://wpimg.wallstcn.com/f778738c-e4f8-4870-b634-56703b4acafe.gif',
      name: 'admin',
      password: '111111',
      desc: '平台管理员',
      roles: ['平台管理员'],
      buttons: ['cuser.detail'],
      routes: [
        'btn.Spu.add',
        'btn.Spu.addSku',
        'btn.Spu.update',
        'btn.Spu.remove',
        'btn.Spu.Search',

        'Product',
        'Trademark',
        'Attribute',
        'Spu',
        'Sku',

        'Acl',
        'User',
        'Role',
        'Permission',
      ],
      token: 'Admin Token',
    },
    {
      userId: 2,
      avatar:
        'https://wpimg.wallstcn.com/f778738c-e4f8-4870-b634-56703b4acafe.gif',
      name: 'system',
      password: '111111',
      desc: '系统管理员',
      roles: ['系统管理员'],
      buttons: ['cuser.detail', 'cuser.user'],
      routes: ['home'],
      token: 'System Token',
    },
  ]
}

export default [
  // 用户登录接口
  {
    url: '/api/user/login', //请求地址
    method: 'post', //请求方式
    response: ({ body }) => {
      //获取请求体携带过来的用户名与密码
      const { username, password } = body
      //调用获取用户信息函数,用于判断是否有此用户
      const checkUser = createUserList().find(
        (item) => item.name === username && item.password === password,
      )

      //没有用户返回失败信息
      if (!checkUser) {
        return { code: 201, data: { message: '账号或者密码不正确' } }
      }
      //如果有返回成功信息
      const { token } = checkUser
      return { code: 200, data: token }
    },
  },
  // 获取用户信息
  {
    url: '/api/user/info',
    method: 'get',
    response: (request) => {
      //获取请求头携带token
      const token = request.headers.token
      //查看用户信息是否包含有次token用户
      const checkUser = createUserList().find((item) => item.token === token)
      //没有返回失败的信息
      if (!checkUser) {
        return { code: 201, data: { message: '获取用户信息失败' } }
      }
      //如果有返回成功信息
      return { code: 200, data: checkUser }
    },
  },

  {
    url: '/api/product/trademark/cate',
    method: 'get',
    response: (request) => {
      console.log(request)
      //如果有返回成功信息
      return {
        code: 200,
        message: '成功',
        data: {
          records,
          total: 24,
          size: 4,
          current: 1,
          searchCount: true,
          pages: 6,
        },
        ok: true,
      }
    },
  },

  {
    url: '/api/product/trademark/save',
    method: 'post',
    response: (request) => {
      console.log(request)
      //如果有返回成功信息
      return {
        code: 200,
        message: '成功',
        data: null,
        ok: true,
      }
    },
  },
  {
    url: '/api/product/trademark/update',
    method: 'post',
    response: (request) => {
      console.log(request)
      //如果有返回成功信息
      return {
        code: 200,
        message: '成功',
        data: null,
        ok: true,
      }
    },
  },
  {
    url: '/api/product/trademark/remove',
    method: 'post',
    response: (request) => {
      console.log(request)
      //如果有返回成功信息
      return {
        code: 200,
        message: '成功',
        data: null,
        ok: true,
      }
    },
  },
  {
    url: '/api/admin/product/fileUpload',
    method: 'post',
    response: (request) => {
      console.log(request)
      //如果有返回成功信息
      return {
        code: 200,
        message: '成功',
        data: 'https://fanyi-cdn.cdn.bcebos.com/static/cat/asset/logo.2481f256.png',
        ok: true,
      }
    },
  },
  // --------------------------------------

  {
    url: '/api/product/attribute/cate',
    method: 'get',
    response: (request) => {
      let data
      const { query } = request
      if (query.level == 1) {
        // 1级
        data = cate_1
      } else if (query.level == 2) {
        // 2级
        data = cate_2
      } else if (query.level == 3) {
        // 3级
        data = cate_3
      }
      console.log(request)
      //如果有返回成功信息
      return {
        code: 200,
        message: '成功',
        data,
        ok: true,
      }
    },
  },

  {
    url: '/api/product/attribute/list',
    method: 'get',
    response: (request) => {
      console.log(request)
      //如果有返回成功信息
      return {
        code: 200,
        message: '成功',
        data: cate_attr_list,
        ok: true,
      }
    },
  },

  {
    url: '/api/product/attribute/save',
    method: 'post',
    response: (request) => {
      console.log(request)
      //如果有返回成功信息
      return {
        code: 200,
        message: '成功',
        data: null,
        ok: true,
      }
    },
  },
  {
    url: '/api/product/attribute/update',
    method: 'post',
    response: (request) => {
      console.log(request)
      //如果有返回成功信息
      return {
        code: 200,
        message: '成功',
        data: null,
        ok: true,
      }
    },
  },
  {
    url: '/api/product/attribute/remove',
    method: 'post',
    response: (request) => {
      console.log(request)
      //如果有返回成功信息
      return {
        code: 200,
        message: '成功',
        data: null,
        ok: true,
      }
    },
  },

  //   ----------------------------------
  {
    url: '/api/product/spu/list',
    method: 'get',
    response: (request) => {
      console.log(request)
      //如果有返回成功信息
      return {
        code: 200,
        message: '成功',
        data: {
          records: spu_records,
          total: 24,
          size: 4,
          current: 1,
          searchCount: true,
          pages: 6,
        },
        ok: true,
      }
    },
  },

  {
    url: '/api/product/spu/add',
    method: 'post',
    response: (request) => {
      console.log(request)
      //如果有返回成功信息
      return {
        code: 200,
        message: '成功',
        data: null,
        ok: true,
      }
    },
  },
  {
    url: '/api/product/spu/update',
    method: 'post',
    response: (request) => {
      console.log(request)
      //如果有返回成功信息
      return {
        code: 200,
        message: '成功',
        data: null,
        ok: true,
      }
    },
  },
  {
    url: '/api/product/spu/remove',
    method: 'post',
    response: (request) => {
      console.log(request)
      //如果有返回成功信息
      return {
        code: 200,
        message: '成功',
        data: null,
        ok: true,
      }
    },
  },

  {
    url: '/api/product/spu/trademark/list',
    method: 'get',
    response: (request) => {
      console.log(request)
      //如果有返回成功信息
      return {
        code: 200,
        message: '成功',
        data: records,
        ok: true,
      }
    },
  },

  {
    url: '/api/product/spu/saleattr/list',
    method: 'get',
    response: (request) => {
      console.log(request)
      //如果有返回成功信息
      return {
        code: 200,
        message: '成功',
        data: saleattr_records,
        ok: true,
      }
    },
  },

  {
    url: '/api/product/spu/id/imagelist',
    method: 'get',
    response: (request) => {
      console.log(request)
      //如果有返回成功信息
      return {
        code: 200,
        message: '成功',
        data: spu_imglist,
        ok: true,
      }
    },
  },
  {
    url: '/api/product/spu/id/attrlist',
    method: 'get',
    response: (request) => {
      console.log(request)
      //如果有返回成功信息
      return {
        code: 200,
        message: '成功',
        data: spu_attrlist,
        ok: true,
      }
    },
  },

  {
    url: '/api/product/spu/id/skulist',
    method: 'get',
    response: (request) => {
      console.log(request)
      //如果有返回成功信息
      return {
        code: 200,
        message: '成功',
        data: sku_list,
        ok: true,
      }
    },
  },

  {
    url: '/api/acl/user/list',
    method: 'get',
    response: (request) => {
      console.log(request)
      //如果有返回成功信息
      return {
        code: 200,
        message: '成功',
        data: {
          records: user_list,
          total: 24,
          size: 4,
          current: 1,
          searchCount: true,
          pages: 6,
        },
        ok: true,
      }
    },
  },

  {
    url: '/api/acl/role/list',
    method: 'get',
    response: (request) => {
      console.log(request)
      //如果有返回成功信息
      return {
        code: 200,
        message: '成功',
        data: {
          records: role_list,
          total: 24,
          size: 4,
          current: 1,
          searchCount: true,
          pages: 6,
        },
        ok: true,
      }
    },
  },
  {
    url: '/api/acl/role/id/list',
    method: 'get',
    response: (request) => {
      console.log(request)
      //如果有返回成功信息
      return {
        code: 200,
        message: '成功',
        data: ROLE_MY_LIST,
        ok: true,
      }
    },
  },
  {
    url: '/api/acl/permission/list',
    method: 'get',
    response: (request) => {
      console.log(request)
      //如果有返回成功信息
      return {
        code: 200,
        message: '成功',
        data: ALL_ROLE_LIST,
        ok: true,
      }
    },
  },
]
